// 侧边栏数据vuex
const asideOptions = {
    namespaced: true,//开启命名空间
    actions:{
        changeCollapse(context,value){
            context.commit('CHANGECOLLAPSE')
        },
        changeMenu(context,value){
            context.commit('CHANGEMENU',value)
        },
        clearMenu(context,value){
            context.commit('CLEARMENU',value)
        }
    },
    mutations:{
        // 切换isCollapse的值
        CHANGECOLLAPSE(state,value){
            state.isCollapse = !state.isCollapse
        },
        // 改变路由
        CHANGEMENU(state,value){
            state.menu = value
            sessionStorage.setItem('baseinfo',JSON.stringify(value))
        },
        // 清除
        CLEARMENU(state,value){
            state.menu = []
            sessionStorage.removeItem('baseinfo')
        },
        // 添加路由
        ADDROUTER(state,router){
            let baseInfo = sessionStorage.getItem('baseinfo')
            if(state.menu.length == 0)
            state.menu = JSON.parse(baseInfo) || []
            
            if(router.options.routes[0].children.length == 0){
                state.menu.forEach(element => {
                    element.component = () => import(`@/view${element.url}`)
                    router.addRoute('main',element)
                });
            }
            // router.addRouters(state.menu)
        }
    },
    state:{
        isCollapse: false, // 侧边栏是否折叠
        menu:[]
    },
    getters:{
        title(state){
            if(state.isCollapse){
                return "后台"
            }else{
                return "通用后台管理系统"
            }
        }
    }
}
export default asideOptions